#ifndef CT_SERVICE_H_
#define	CT_SERVICE_H_

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <unistd.h>
#include "ct_noncopyable.h"
#include "ct_properties.h"

class ctService:private ctNoncopyable
{
        public:
                virtual ~ctService() { serviceInst_ = NULL; }
                virtual void reloadConfig() { }
                bool isTerminate() const { return terminate_; }
                void Terminate() { terminate_ = true; }
                static ctService *serviceInstance() { return serviceInst_; }
                void main();

                ctProperties env_;

        protected:
                ctService(const std::string &name)
                        : name_(name)
                {
                        serviceInst_ = this;
                        terminate_ = false;
                }
                virtual bool init();
                virtual bool validate()
                {
                        return true;
                }
                virtual bool serviceCallBack() = 0;
                virtual void final() = 0;

        private:
                static ctService *serviceInst_;
                std::string name_;
                bool terminate_;
};

#endif //CT_SERVICE_H_

